<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <!-- Do not output XML declaration -->
	<xsl:output omit-xml-declaration="yes"/>
  <!-- Root template -->
	<xsl:template match="/">
		<xsl:copy>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

	<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
	<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>

	<xsl:template name="csFunctionDoc" match="refentry">
		<!-- Summary section -->
		<summary>
			<xsl:text>&#xA;</xsl:text>
			<!-- Note: make sure that first letter is upper case -->
			<xsl:value-of select="concat(
					translate(substring(refnamediv/refpurpose, 1, 1), $lowercase, $uppercase),
					substring(refnamediv/refpurpose, 2, string-length(refnamediv/refpurpose) - 1))"/>
			<xsl:text>.&#xA;</xsl:text>
		</summary>
		<xsl:text>&#xA;</xsl:text>

		<!-- Parameter descriptions -->
		<xsl:for-each select="refsect1/variablelist/varlistentry">
			<xsl:choose>
				<xsl:when test="../../@id = 'parameters'">
					<param name="{term/parameter}">
						<xsl:text>&#xA;</xsl:text>
						<xsl:for-each select="listitem/para">
							<xsl:apply-templates/>
						</xsl:for-each>
					</param>
					<xsl:text>&#xA;</xsl:text>
				</xsl:when>
			</xsl:choose>
		</xsl:for-each>

		<!-- Remarks section -->
		<remarks>
			<!-- Long description -->
			<xsl:text>&#xA;</xsl:text>
			<para>
				<xsl:text>&#xA;</xsl:text>
				<!-- Function documentation -->
				<xsl:for-each select="refsect1[@id='description']/para | refsect1[@id='description']/programlisting | refsect1[@id='description']/variablelist">
					<xsl:apply-templates/>
					<xsl:text>&#xA;</xsl:text>
				</xsl:for-each>
			</para>
			<xsl:text>&#xA;</xsl:text>
			<!-- Special notes -->
			<xsl:for-each select="refsect1[@id='notes']/para">
				<para>
					<xsl:text>&#xA;</xsl:text>
					<xsl:apply-templates/>
				</para>
				<xsl:text>&#xA;</xsl:text>
			</xsl:for-each>
			<!-- Function error list -->
			<xsl:if test="count(//refsect1[@id='errors']/para) > 0">
				<para>
					This routine generates the following errors (detectable with <see cref="glGetError"/>):
					<xsl:for-each select="refsect1[@id='errors']/para">
						- <xsl:apply-templates/>
					</xsl:for-each>
				</para>
				<xsl:text>&#xA;</xsl:text>
			</xsl:if>
			<!-- Associated gets -->
			<xsl:if test="count(//refsect1[@id='associatedgets']/para) > 0">
				<para>
					<xsl:text>&#xA;</xsl:text>
					Here is the list of the associated "get" routines: <br/>
					<xsl:for-each select="refsect1[@id='associatedgets']/para">
						<xsl:text>&#xA;</xsl:text>
						- <xsl:apply-templates/>
					</xsl:for-each>
				</para>
				<xsl:text>&#xA;</xsl:text>
			</xsl:if>
			<!-- Function documentation copyright -->
			<xsl:if test="count(//refsect1[@id='Copyright']/para) > 0">
				<hr/>
				<xsl:text>&#xA;</xsl:text>
				<para>
					<xsl:text>&#xA;</xsl:text>
					<i>This is an adaptation of the original documentation found at https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/docs.</i>
					<xsl:text>&#xA;</xsl:text>
					<i>Documentation copyright reference:</i>
					<xsl:for-each select="refsect1[@id='Copyright']/para">
						<para>
							<xsl:text>&#xA;</xsl:text>
							<i><xsl:apply-templates/></i>
						</para>
						<xsl:text>&#xA;</xsl:text>
					</xsl:for-each>
				</para>
				<xsl:text>&#xA;</xsl:text>
			</xsl:if>
		</remarks>
		<xsl:text>&#xA;</xsl:text>
		<!-- See also list -->
		<xsl:for-each select="refsect1[@id = 'seealso']/para/citerefentry">
			<seealso cref="{refentrytitle}"/>
			<xsl:text>&#xA;</xsl:text>
		</xsl:for-each>
	</xsl:template>

	<!-- Constant renaming: 'GL_FOO' -> 'GL.FOO' -->
	<xsl:template match="para/constant">
		<see cref="{.}"/>
	</xsl:template>
	<xsl:template match="term/constant">
		<see cref="{.}"/>
	</xsl:template>

	<!-- Function renaming: 'glFoo' -> 'Gl.Foo' -->
	<xsl:template match="para/function">
		<see cref="{.}"/>
	</xsl:template>
	<xsl:template match="para/citerefentry/refentrytitle">
		<see cref="{.}"/>
	</xsl:template>

	<!-- Parameter reference: 'param' -> <paramref name="param" /> -->
	<xsl:template match="para/parameter">
		<paramref name="{.}"/>
	</xsl:template>

	<!-- Program listing Doxygen markup (<code> does not work, maintains indentation) -->
	<xsl:template match="programlisting/text()">
		@code
		<xsl:value-of select="."/>
		@endcode
	</xsl:template>

	<!-- Variable listing (rendered as dotted point list) -->
	<xsl:template match="variablelist/varlistentry">
		- <xsl:apply-templates select="term/constant"/>: <xsl:apply-templates select="listitem"/>
	</xsl:template>

	<!-- MathML equations -->
	<xsl:template match="para/informalequation">
		@htmlonly <informalequation><xsl:copy-of select="*"/></informalequation> @endhtmlonly
	</xsl:template>
	<xsl:template match="para/inlineequation">
		@htmlonly <inlineequation><xsl:copy-of select="*"/></inlineequation> @endhtmlonly
	</xsl:template>
</xsl:stylesheet>